package com.zhizuobiao.coura.application;

import android.app.Application;

import com.zhizuobiao.coura.stock.HAStockService;
import com.zhizuobiao.coura.stock.HHStockService;
import com.zhizuobiao.coura.stock.HKStockService;
import com.zhizuobiao.coura.stock.SHStockService;
import com.zhizuobiao.coura.weather.WeatherService;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by coura on 2016/12/13.
 */

public class MyApplication extends Application {

    private static final String BASE_URL = "http://web.juhe.cn:8080/";
    private static final String WEATHER_BASE_URL = "http://api.map.baidu.com/";
    private HKStockService hkStockService;
    private HAStockService haStockService;
    private SHStockService shStockService;
    private HHStockService hhStockService;
    private WeatherService weatherService;

    @Override
    public void onCreate() {
        hkStockService = (HKStockService) getService(BASE_URL,HKStockService.class);
        haStockService = (HAStockService) getService(BASE_URL,HAStockService.class);
        shStockService = (SHStockService) getService(BASE_URL,SHStockService.class);
        hhStockService = (HHStockService) getService(BASE_URL,HHStockService.class);
        weatherService = (WeatherService) getService(WEATHER_BASE_URL,WeatherService.class);
    }

    private Object getService(String url,Class clazz){
        return new Retrofit.Builder()
                .baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(clazz);
    }

    public HKStockService getHkStockService(){
        return hkStockService;
    }

    public HAStockService getHaStockService(){
        return haStockService;
    }

    public SHStockService getShStockService(){
        return shStockService;
    }

    public HHStockService getHhStockService(){
        return hhStockService;
    }

    public WeatherService getWeatherService(){
        return weatherService;
    }
}
